package com.gthncz;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Demo16 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();

        Set<Integer>[] nums = new HashSet[n+10];
        for (int i=0; i<n; ++i) {
            nums[i] = new HashSet<>();
            // nums[i].add(0);
            int x = sc.nextInt();
            while (x-- > 0){
                nums[i].add(sc.nextInt());
            }
        }
        int result = 0;
        for (int i=0; i<n; ++i) {
            int[] count = new int[c+10];

            // 最后一个用例肯定在 n<m

            for (int j=0; j<m; ++j) {
                Set<Integer> set = nums[(i+j) % n];
                for (int item: set){
                    ++ count[item];
                }
            }
            for (int item: count){
                if (item > 1) ++result;
            }
        }

        System.out.printf("%d", result);
    }

}
